<?php

/* *
 * 资讯
 */
namespace Common\Model;
use Think\Model;
class PurchaseModel extends BaseModel {

    public function queryForList($page=null, $map=null) {
        $list = $this->alias("ps")
            ->join("left join __ADMIN__ emp on emp.employee_id = ps.update_id")
            ->join("left join __ADMIN__ auditor on auditor.employee_id = ps.auditor_id")
            ->join("left join __ADMIN__ purchaser on purchaser.employee_id = ps.purchaser_id")
            ->join("left join __STORE__ s on s.store_id = ps.store_id")
            ->join("left join __SUPPLIER__ sp on sp.supplier_id = ps.supplier_id")
            ->where(getWhereSqlByMap($map))
            ->order("ps.update_time desc")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field("ps.*, emp.admin_name, auditor.admin_name as auditor, purchaser.admin_name as purchaser, s.store_name, sp.supplier_name")
            ->select();

        return $list;

    }

    public function getListCount($map = null) {

        $count = $this->alias("ps")
//            ->join("left join __PRODUCT__ p on p.product_id = wo.product_id")
//            ->join("left join __CUSTOMER__ cus on cus.customer_id = wo.customer_id")
            ->where(getWhereSqlByMap($map))
            ->count();

        return $count;
    }

}

